package il.technion.cs236369.webserver;

import java.util.HashMap;

import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

/**
 * @author Sabre Runner
 *
 */
public class HttpContextImpl implements HttpContext
{
		private HttpParams params = null;
		
		public HttpContextImpl(HttpParams params)
		{
			this.params = params;
		}

		/**
		 * Inserts all the given attributes into the context params list
		 * @param attributes
		 */
		public void InsertParams(HashMap<String, String> attributes)
		{
			for (String key : attributes.keySet())
			{
				params.setParameter(key, attributes.get(key));
			}
		}

		@Override
		public Object getAttribute(String key)
		{
			return params.getParameter(key);
		}

		@Override
		public Object removeAttribute(String key)
		{
			Object value = params.getParameter(key);
			if (params.removeParameter(key))
			{
				return value;
			}
			else
			{
				return null;
			}
		}

		@Override
		public void setAttribute(String key, Object value)
		{
			params.setParameter(key, value);
		}

}
